package com.tianji.learning.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.learning.domain.dto.QuestionFormDTO;
import com.tianji.learning.domain.query.QuestionPageQuery;
import com.tianji.learning.domain.vo.QuestionVO;
import com.tianji.learning.service.IInteractionQuestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 互动提问的问题表 前端控制器
 * </p>
 *
 * @author xzh
 * @since 2024-03-14
 */
@RestController
@RequestMapping("/questions")
@Api(tags = "提问相关接口")
@AllArgsConstructor(onConstructor_={@Lazy} )
public class InteractionQuestionController {

    private final IInteractionQuestionService interactionQuestionService;

    /**
     * 保存前端发送的问题
     * @param questionFormDTO
     */
    @PostMapping
    @ApiOperation(value = "保存前端发送的问题")
    public void saveQuestion(@RequestBody QuestionFormDTO questionFormDTO){
    interactionQuestionService.saveQuestion(questionFormDTO);
    }

    /**
     * 修改问题
     * @param id
     * @param questionFormDTO
     */
    @PutMapping("/{id}")
    @ApiOperation(value = "修改问题")
    public void updateQuestion(@PathVariable(value = "id") Long id,@RequestBody QuestionFormDTO questionFormDTO){
    interactionQuestionService.updateQuestion(id,questionFormDTO);
    }

    /**
     * 分页根据条件查询我的问题
     * @param query
     * @return
     */
    @GetMapping("/page")
    @ApiOperation(value = "分页根据条件查询我的问题")
    public PageDTO<QuestionVO> queryQuestionPage(QuestionPageQuery query){
        return interactionQuestionService.queryQuestionPage(query);
    }

    /**
     * 根据问题id查询问题详情
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "根据问题id查询问题详情")
    public QuestionVO queryQuestionById(@PathVariable(value = "id") Long id){
        return interactionQuestionService.queryQuestionById(id);
    }

    /**
     * 删除我的问题
     * @param id
     */
    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除我的问题")
    public void deleteMyQuestionById(@PathVariable(value = "id") Long id){
        interactionQuestionService.deleteMyQuestionById(id);
    }
}
